package org.springframework.aop.framework;

import org.springframework.aop.AdvisedSupport;

/**
 * @Name AopProxyFactory
 * @Description: AOP 代理工厂类
 * 描述信息：由 AdvisedSupport#proxyTargetClass 属性决定使用 JDK 动态代理实现类还是 CGLIB 动态代理实现类。
 * @Version v1.0.0
 * @Author: lichao
 * @Date: 2024-03-27 17:45:10
 **/
public class AopProxyFactory extends AdvisedSupport {

    public AopProxyFactory() {
    }

    public Object getAopProxy() {
        return createAopProxy().getProxy();
    }

    private AopProxy createAopProxy() {
        // 当我们设置 proxyTargetClass 属性或者被代理对象没有接口时会调用 CGLIB 动态代理，否则调用 JDK 动态代理。
        if (this.isProxyTargetClass() || this.getTargetSource().getTargetClass().length == 0) {
            return new CglibDynamicAopProxy(this);
        }
        return new JdkDynamicAopProxy(this);
    }

}

